package cn.lix.sc.elasticsearch.utils;

import cn.lix.sc.elasticsearch.dto.Condition;

import java.util.List;

public class TransferConditions {

    public static void transfer(List<Condition> conditions, ESQueryHelper helper){
        for (Condition condition : conditions) {
            switch (condition.getOptType()){
                case LIKE:
                    helper.and(ESQueryHelper.like(condition.getField(), condition.getValue()));
                    continue;
                case IN:
                    helper.and(ESQueryHelper.in(condition.getField(), condition.getValue()));
                    continue;
                case EQUAL:
                    helper.and(ESQueryHelper.equals(condition.getField(), condition.getValue()));
                    continue;
                case LT:
                    helper.and(ESQueryHelper.lt(condition.getField(), condition.getValue()));
                    continue;
                case GT:
                    helper.and(ESQueryHelper.gt(condition.getField(), condition.getValue()));
                    continue;
                case QUERY:
                    helper.and(ESQueryHelper.queryString(condition.getField(), condition.getValue()));
                    continue;
                case MATCH:
                    helper.and(ESQueryHelper.match(condition.getField(), condition.getValue()));
                    continue;
                case REGEXP:
                    helper.and(ESQueryHelper.regexp(condition.getField(), String.valueOf(condition.getValue())));
                    continue;
                case ALL:
                    helper.and(ESQueryHelper.queryAll());
                    continue;
                case IDS:
                    helper.and(ESQueryHelper.ids());
                    continue;
                case FROM:
                    helper.from((Number) condition.getValue());
                    continue;
                case SIZE:
                    helper.size((Number) condition.getValue());
                    continue;
                case AES:
                    helper.asc(condition.getField());
                    continue;
                case DESC:
                    helper.desc(condition.getField());
                    continue;
                default:
                    throw new RuntimeException("不支持的操作");
            }
        }
    }

}
